package org.space.galaxyCabinet;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Component;

@Component
public class RabbitMQUtil {

    private final AmqpTemplate amqpTemplate;

    public RabbitMQUtil(AmqpTemplate amqpTemplate) {
        this.amqpTemplate = amqpTemplate;
    }

    /**
     * 发送消息到指定队列
     *
     * @param queueName 队列名称
     * @param message   消息内容
     */
    public void sendMessage(String queueName, Object message) {
        amqpTemplate.convertAndSend(queueName, message);
    }

    /**
     * 发送消息到指定交换机
     *
     * @param exchange   交换机名称
     * @param routingKey 路由键
     * @param message    消息内容
     */
    public void sendMessage(String exchange, String routingKey, Object message) {
        amqpTemplate.convertAndSend(exchange, routingKey, message);
    }
}
